﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using 医院预约Web.Models;

namespace 医院预约Web.Controllers
{
    public class AdminController : Controller
    {
        public IActionResult Index()
        {
            string account = HttpContext.Session.GetString("name");
            ViewData["account"]=account;
            return View();
        }

        public IActionResult newDoctor()
        {
            return View();
        }
        [HttpPost]
        public void UpdateDoctor2(string DoctorName, string SelectClassNumber, string DoctorSkill,string SelectDoctorType,int id)
        {
            int ClassNumber = 0;
            switch (SelectClassNumber)
            {
                case "请选择":
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
                case "外科":
                    ClassNumber = 1;
                    break;
                case "内科":
                    ClassNumber = 2;
                    break;
                case "儿科":
                    ClassNumber = 3;
                    break;
                case "骨科":
                    ClassNumber = 4;
                    break;
                default:
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
            }
            int DoctorType = 0;
            switch (SelectDoctorType)
            {
                case "请选择":
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
                case "主任医师":
                    DoctorType = 1;
                    break;
                case "副主任医师":
                    DoctorType = 2;
                    break;
                case "主治医师":
                    DoctorType = 3;
                    break;
                default:
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
            }
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if(db.UpdateDoctor( DoctorName,  ClassNumber,  DoctorSkill, DoctorType,id))
                Response.Redirect("dialog?id=6");
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
        [HttpPost]
        public void newDoctor(string DoctorName, string SelectClassNumber, string DoctorSkill, string Password, string SelectDoctorType, string Message,string w1,string w2,string w3, string w4, string w5, string w6,string w7)
        {

            //<class="aui-switch">标签string返回null/'on'
            // 测试代码return DoctorName + "\n" + SelectClassNumber +  "\n" + DoctorSkill + "\n" + Password + "\n" + SelectDoctorType +  "\n" + Message + "\n" +w1 + "\n" +w2 + "\n" +w3;
            string[] w = new string[7] { w1, w2, w3, w4, w5,w6,w7 };
            int[] iw = new int[7];
            for (int i = 0; i <=6; i++)
            {
                if (w[i] == "on")
                {
                    iw[i] = 1;
                }
                else iw[i] = 0;
            }
            //return  DoctorName + "\n" + SelectClassNumber + "\n" + DoctorSkill + "\n" + Password + "\n" + SelectDoctorType + "\n" + Message + "\n" + w1 + "\n" + w2 + "\n" + w3 + "\n" + iw[1] + "\n" + iw[2] + "\n" + iw[3] + "\n" + iw[4] + "\n" + iw[5] + "\n" + iw[6] + "\n";

            int ClassNumber = 0;
            switch (SelectClassNumber)
            {
                case "请选择":
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
                case "外科":
                    ClassNumber = 1;
                    break;
                case "内科":
                    ClassNumber = 2;
                    break;
                case "儿科":
                    ClassNumber = 3;
                    break;
                case "骨科":
                    ClassNumber = 4;
                    break;
                default:
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
            }
            int DoctorType = 0;
            switch (SelectDoctorType)
            {
                case "请选择":
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
                case "主任医师":
                    DoctorType = 1;
                    break;
                case "副主任医师":
                    DoctorType = 2;
                    break;
                case "主治医师":
                    DoctorType = 3;
                    break;
                default:
                    Response.Redirect(Url.Action("LoginError", "Home"));
                    break;
            }
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            System.DateTime CreateTime = new System.DateTime();
            CreateTime = System.DateTime.Now;//yyyy-MM-dd HH:mm:ss
                                             // 测试代码2return DoctorName + "\n" + SelectClassNumber +  "\n" + DoctorSkill + "\n" + Account + "\n" + Password + "\n" + SelectDoctorType +  "\n" + Message;
            int id = db.newDoctor(DoctorName, ClassNumber, DoctorSkill, Password, DoctorType, CreateTime, Message,iw[0], iw[1], iw[2], iw[3], iw[4], iw[5], iw[6]);
            Response.Redirect("dialog?id="+id);
        }
        public IActionResult Dialog(int ID)
            {//id=0000:newDoctor
            //id=2:UpdateWeekdbo
                ViewData["ID"] = ID;
                return View();
            }
        
        public IActionResult UploadImage()
        {
            return View();
        }
        public IActionResult UpdateWeekdbo()
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetAllDoctordbo());
        }
        public IActionResult UpdateWeekdboII(int id, string doctorname, int classnumber)
        {
            string kesi = "";
            switch (classnumber)
            {
                case 1:
                    kesi = "外科";
                    break;
                case 2:
                    kesi = "内科";
                    break;
                case 3:
                    kesi = "儿科";
                    break;
                case 4:
                    kesi = "骨科";
                    break;
            }
            ViewData["id"] = id;
            ViewData["DocterName"] = doctorname;
            ViewData["ClassNumber"] = kesi;
           
            return View();
        }
        [HttpPost]
        public void UpdateWeekdboII(int id, string w1, string w2, string w3, string w4, string w5, string w6, string w7)
        {
            string[] w = new string[7] { w1, w2, w3, w4, w5, w6, w7 };
            int[] iw = new int[7];
            for (int i = 0; i <= 6; i++)
            {
                if (w[i] == "on")
                {
                    iw[i] = 1;
                }
                else iw[i] = 0;
            }
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if (db.UpdateWeekdbo(id, iw[0], iw[1], iw[2], iw[3], iw[4], iw[5], iw[6]))
                Response.Redirect("dialog?id=2");
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
        public void UpdateWeekdboIII(int id, int d1, int d2, int d3, int d4, int d5, int d6, int d7)
        {
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if (db.UpdateWeekdbo(id, d1, d2, d3, d4, d5, d6, d7))
            {
                db.DeleteWeekdboMessage(id);
                Response.Redirect("dialog?id=2");
            }
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
        public IActionResult Weekdbo()
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetAllWeekdbo());
        }
        public void dbshow()
        {
            Response.Redirect(Url.Action("ae99fee77bffd211851b7d", "Vip"));
        }
        public IActionResult freezeoff(string id)
        {
            ViewData["id"] = id;
            return View();
        }
        public void nofreeze(string id)
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            context.update(id, "1");
            context.deletenofreezemessage(id);
            Response.Redirect(Url.Action("index", "Admin"));
        }
        public IActionResult weekdbochange(string id)
        {
            ViewData["id"] = id;
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetOnesWeekdbo(id));
        }
        
        public IActionResult dbquest()
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetNoFreezeMessage());
        }
        public IActionResult dbquest2()
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetWeekdboUpdateMessage());
        }
            public IActionResult UpdateClass()//科室
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetClassdbos());
        }
        
            public IActionResult UpdateClass2(int classnum,string classname,string classplace)//科室
        {
            ViewData["classnum"] = classnum;
            ViewData["classname"] = classname;
            ViewData["classplace"] = classplace;
            return View();
        }
        [HttpPost]
        public void UpdateClass3(int classnum, string classname,string classplace)//科室
        {
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if (db.UpdateClass(classnum,classname,classplace))
                Response.Redirect("dialog?id=4");
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
        public IActionResult NewClass()
        {
            return View();
        }
        [HttpPost]
        public void NewClass(string classname,string classplace)
        {
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if (db.NewClass( classname, classplace))
                Response.Redirect("dialog?id=5");
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
        public IActionResult UpdateDoctor()
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            return View(context.GetAllWeekdbo());
        }
        public IActionResult UpdateDoctor2(int id)
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            ViewData["id"]=id;
            return View(context.GetDoctor(id));
        }
        public void UpdateDoctor3(int id)
        {
            DataBase context = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if(context.UpdateDoctor2(id))
            Response.Redirect("dialog?id=6");
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
    }
}